import java.util.ArrayList;
import java.util.List;

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.pubsub.Subscription;

/*
 * N. Dumont, TAI Lab
 *
 * Class GetSubscribers created on 20 mai 2011
 *
 * Copyright (c) 2009 Thales Communications
 * 160 bd de Valmy - BP82 92704 COLOMBES cedex - France
 * All rights reserved.
 *
 */

/**
 * @author tai
 * 
 */
public class GetSubscribers {
	public static void main(String[] args) {
		GetSubscribers g = new GetSubscribers();
		g.start();
	}

	/**
 * 
 */
	private void start() {
		ConnectionConfiguration config = new ConnectionConfiguration("192.168.20.12", 5222);
		XMPPConnection connection = new XMPPConnection(config);
		try {
			connection.connect();
			connection.login("phidget", "phidget");
		} catch (XMPPException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		List<String> nodes = new ArrayList<String>();
		PubSubManager manager = new PubSubManager(connection);
		try {
			List<Subscription> s = manager.getSubscriptions();
			
			for (Subscription l_subscription : s) {
				deleteNode(manager,l_subscription.getNode());
			}
		} catch (XMPPException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		

	}
	
	private void deleteNode(PubSubManager manager , String nodeName){
		try {
			manager.deleteNode(nodeName);
			System.out.println(nodeName + " deleted.");
		} catch (XMPPException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
